/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package webprocessors;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.LinkedList;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import readers.UserReader;

/**
 *
 * @author Chris
 */
public class webprocessorShowTests extends webprocessor {
    public webprocessorShowTests() {}
    
    @Override
    public String process(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        String user = getUserName(request);
        LinkedList<String> grps = new LinkedList<String>();
        LinkedList<String> tests = new LinkedList<String>();
        
        if(!UserReader.getTeacherGroups(user, grps)) {
            return "Please add a group";
        }
        
        String grp;
        String test;
        String output = "<table><tr><td>Group</td><td>Test</td><td>Scores</td>"+
                "<td>Word List</td></tr>";   
        while(!grps.isEmpty()) {
            grp = grps.removeFirst();
        
            if(!UserReader.getTests(user, grp, tests)) {
                output += "<tr><td>No Tests</td><td></td><td></td></tr>";
                continue;
            }
                        
            while(!tests.isEmpty()) {
                test = tests.removeFirst();
                output += "<tr><td>" + grp + "</td><td>"+test+"</td><td><a href='test.jsp?" +
                        "tid=" + test + "&grpid=" + grp + "'>Scores" + "</a></td><td><a href='words.jsp?" +
                        "grpid=" + grp + "&testid="+test+"'>Words</a></td>" +
                        "</a></td></tr>";
            }
        }
        output += "</table>";
        
        return output;
    }

}
